<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="设备名称" prop="deviceName">
            <el-input v-model="form.deviceName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="设备编号">
            <el-input v-model="form.deviceCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="设备类型">
            <!--<el-input v-model="form.deviceType" style="width: 370px;" />-->
            <el-select v-model="form.deviceType" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.equ_type"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <!--<el-form-item label="所在区域">-->
          <!--<el-input v-model="form.region" style="width: 370px;" />-->
          <!--</el-form-item>-->

          <el-form-item label="所在区域">
            <el-select v-model="form.areaId" placeholder="请选择" style="width: 370px">
              <el-option v-for="item in areas" :key="item.id" :label="item.areaName" :value="item.id" />
            </el-select>
          </el-form-item>

          <el-form-item label="模型坐标">
            <el-input v-model="form.modelCoordinates" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="deviceName" label="设备名称" />
        <el-table-column prop="deviceCode" label="设备编号" />
        <el-table-column prop="deviceType" label="设备类型">
          <template slot-scope="scope">
            {{ dict.label.equ_type[scope.row.deviceType] }}
          </template>
        </el-table-column>
        <el-table-column prop="areaName" label="所在区域" />
        <!--<el-table-column prop="areaMonitorName" label="区域监控" />-->

        <el-table-column prop="modelCoordinates" label="模型坐标" />
        <el-table-column v-permission="['admin','deviceSettingManage:edit','deviceSettingManage:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />

            <button @click="routerTo(scope.row.id)">详情</button>

          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      </el-dialog></div>
  </div>
</template>

<script>
import crudAreas from '@/api/system/areaManage'
import crudDeviceSettingManage from '@/api/mhm/deviceSettingManage'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, createTime: null, updateTime: null, createBy: null, updateBy: null, deviceName: null, deviceCode: null, deviceType: null, areaId: null, modelCoordinates: null }
export default {
  name: 'DeviceSettingManage',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['equ_type'],

  cruds() {
    return CRUD({ title: '设备设施管理', url: 'api/deviceSettingManage', sort: 'id,desc', crudMethod: { ...crudDeviceSettingManage }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'deviceSettingManage:add'],
        edit: ['admin', 'deviceSettingManage:edit'],
        del: ['admin', 'deviceSettingManage:del']
      },
      areas: [],
      rules: {
        deviceName: [
          { required: true, message: '设备名称不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      this.initSelect()
      return true
    },
    routerTo(id) {
      console.log(id)
      this.$router.push({ path: '/deviceSettingManage', query: { deviceSettingManageId: id }})
    },
    initSelect() {
      crudAreas.getAreaList().then(res => {
        console.log(res)
        this.areas = res.content
      })
    }
  }
}
</script>

<style scoped>

</style>
